package com.thinkgem.jeesite.modules.euler.sdk;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.thinkgem.jeesite.modules.euler.sdk.base.Client;
import com.thinkgem.jeesite.modules.euler.sdk.base.Command;
import com.thinkgem.jeesite.modules.euler.sdk.cmd.MonitorBegin;
import com.thinkgem.jeesite.modules.euler.sdk.cmd.MonitorEnd;

/**
 * @describe:
 * @author leo E-mail: zhangle231@163.com
 * @version 下午2:01:47
 */
public class EulerMonitorClient extends Client {

	public void begin(String taskId) {

	}

	/**
	 * resultCode : 0 成功 非0 失败
	 * 
	 * @param taskId
	 * @param resultCode
	 */
	public void end(String taskId, int resultCode) {

	}

	/**
	 * 记录监控数据
	 * 
	 * @param args
	 * @throws Throwable
	 */
	public static void main(String[] args) throws Throwable {
		exeCommand(args);
	}

	public static void exeCommand(String[] args) throws Throwable {
		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
				new String[] { "spring-context.xml", "spring-sdk.xml" });
		
		CommandFactory commandFactory = (CommandFactory)ctx.getBean("commandFactory");
		
		List<Command> cmdList = new ArrayList<Command>();
		cmdList.add(new MonitorBegin());
		cmdList.add(new MonitorEnd());

		commandFactory.registerAllCmd();

		commandFactory.initCommandLine(args);

		commandFactory.executeCommand();
		
		ctx.close();
	}

	// public static void main1(String[] args) throws Throwable {
	//
	// Options options = new Options();
	// options.addOption("task_name", true, "result code");
	// options.addOption("type", true, "monitor type");
	// options.addOption("result", true, "result code");
	//
	// CommandLineParser parser = new PosixParser();
	// CommandLine cmd = parser.parse(options, args);
	//
	// CommandFactory.initCommandLine();
	//
	// command = CommandFactory.createCommand(cmd);
	// command.execute();
	//
	//
	// String taskName;
	// String type;
	// String result;
	// if (cmd.hasOption("task_name")) {
	// taskName = cmd.getOptionValue("task_name");
	// System.out.println(taskName);
	// }
	//
	// if (cmd.hasOption("type")) {
	// type = cmd.getOptionValue("type");
	// System.out.println(type);
	// }
	//
	// if (cmd.hasOption("result")) {
	// String countryCode = cmd.getOptionValue("c");
	// System.out.println(countryCode);
	// }
	//
	// // AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
	// // new String []{"spring-context.xml"});
	// //
	// // MonitorService bean = (MonitorService) ctx.getBean("monitorService");
	// // TaskStatEntity entity = new TaskStatEntity();
	// // bean.save(entity);
	// // ctx.close();
	// }

}
